#ifndef SDK_OHOS_OHOS_RTP_RECEIVER_H_
#define SDK_OHOS_OHOS_RTP_RECEIVER_H_

#include "api/ohos_rtp_receiver_interface.h"
#include "api/ohos_peer_connection_factory_interface.h"

namespace ohoswebrtc {

class OHOSRtpReceiver : public OHOSRtpReceiverInterface, webrtc::RtpReceiverObserverInterface {
 public:
  OHOSRtpReceiver(rtc::scoped_refptr<webrtc::RtpReceiverInterface> rtp_receiver, rtc::scoped_refptr<OHOSPeerConnectionFactoryInterface> peer_connection_factory);
  virtual ~OHOSRtpReceiver();

  /** The OHOSMediaTrack associated with the receiver. */
  rtc::scoped_refptr<OHOSMediaTrackInterface> track() const override;

   /** The list of stream_ids that `track` is associated with.  */
  const std::vector<std::string> stream_ids() const override {
    return rtp_receiver_->stream_ids();
  }
  /** The list of streams that `track` is associated with.  */
  std::vector<rtc::scoped_refptr<OHOSMediaStreamInterface>> streams() const override;

  /**media type for Audio or video receiver */
  cricket::MediaType media_type() const override {
    return rtp_receiver_->media_type();
  }
  
  /**temporarily use to uniquely identify a receiver until we implement Unified Plan SDP */
  const std::string received_id() const override {
    return rtp_receiver_->id();
  }
  
  /**The WebRTC specification only defines RTCRtpParameters in terms of senders */
  webrtc::RtpParameters parameters() const override {
    return rtp_receiver_->GetParameters();
  }

  /** Sets a user defined frame decryptor that will decrypt the entire frame before it is sent across the network. */
  void SetFrameDecryptor(rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor) override {
    rtp_receiver_->SetFrameDecryptor(frame_decryptor);
  }

  rtc::scoped_refptr<webrtc::FrameDecryptorInterface> frame_decryptor() const override {
    return rtp_receiver_->GetFrameDecryptor();
  }
  
  /** Sets a frame transformer between the depacketizer and the decoder to enable
   * client code to transform received frames according to their own processing logic
  **/
  void SetDepacketizerToDecoderFrameTransformer(
      rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) override {
    rtp_receiver_->SetDepacketizerToDecoderFrameTransformer(frame_transformer);
  }

  /** Default implementation of SetFrameTransformer. */
  void SetFrameTransformer(rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) override {
    rtp_receiver_->SetFrameTransformer(frame_transformer);
  }

  /**
   * register OnFirstPacketReceived Observer
   */
  void RegisterObserver(OHOSRtpReceiverObserver* observer) override;
  
  /**
   * RtpReceiverInterface representation of this OHOSRtpReceiver object. This is
   * needed to pass to the underlying C++ APIs.
   */
  rtc::scoped_refptr<webrtc::RtpReceiverInterface> rtp_receiver() const override {
    return rtp_receiver_;
  }

  /**
   * Sets the jitter buffer minimum delay until media playout. Actual observed
   * delay may differ depending on the congestion control. `delay_seconds` is a
   * positive value including 0.0 measured in seconds. `nullopt` means default
   * value must be used.
   */
  void SetJitterBufferMinimumDelay(double delay_seconds) override;

  void OnFirstPacketReceived(cricket::MediaType media_type) override; 

 private:
  rtc::scoped_refptr<webrtc::RtpReceiverInterface> rtp_receiver_;
  OHOSRtpReceiverObserver* observer_;
  rtc::scoped_refptr<OHOSPeerConnectionFactoryInterface> peer_connection_factory_;

};

}  

#endif  